package cn.bearspark.api.controller.main;

import cn.bearspark.api.service.main.VideoService;
import cn.bearspark.api.vo.main.video.PlayVideoVO;
import cn.bearspark.api.vo.main.video.PublishVideoVO;
import cn.bearspark.api.vo.main.video.VideoListVO;
import cn.bearspark.common.dto.Page;
import cn.bearspark.framework.web.starter.vo.ResponseVO;
import jakarta.validation.constraints.Max;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 视频模块
 *
 * @author f
 */
@Validated
@RestController
@RequestMapping("/video")
public class VideoController {

    private final VideoService videoService;

    public VideoController(VideoService videoService) {
        this.videoService = videoService;
    }

    /**
     * 发布视频
     *
     * @param publishVideoVO 发布视频的请求
     * @return 响应
     */
    @PostMapping
    public ResponseVO<Object> publishVideo(@RequestBody PublishVideoVO publishVideoVO) {
        videoService.publishVideo(publishVideoVO);
        return ResponseVO.success();
    }

    /**
     * 播放视频
     *
     * @param videoId 待播放的视频 id
     * @return 响应，响应体：待播放视频的信息
     */
    @GetMapping("/play/{videoId}")
    public ResponseVO<PlayVideoVO> playVideo(@PathVariable("videoId") Long videoId) {
        return ResponseVO.success(videoService.playVideo(videoId));
    }

    /**
     * 获取视频列表
     *
     * @param page 页数
     * @param size 元素数，最大为 50
     * @return 响应，响应体：视频的分页查询对象
     */
    @GetMapping("/list/{page}/{size}")
    public ResponseVO<Page<VideoListVO>> getVideoList(@PathVariable("page") Integer page,
                                                      @Max(50) @PathVariable("size") Integer size) {
        return ResponseVO.success(videoService.getVideoList(page, size));
    }
}
